﻿using AutoMapper;
using BasicInformationWrite.API.BasicInformationCommons.Materialss;
using ERPSystem.Common.Domains.Material;
using ERPSystem.Common.DTO;
using ERPSystem.Enum.CommonErrorCodes;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace BasicInformationWrite.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MaterwriteController : Controller
    {
        private readonly IMediator _mediator;

        public MaterwriteController(IMediator mediator)
        {
            _mediator = mediator;
        }

        /// <summary>
        /// 新增物料基本档案
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> AddMaterialInform(MaterialssCreateCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var result = await _mediator.Send(request, cancellationToken);
                return result;
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 物料分类添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public async Task<Result> Handle(MaterialCascadeCreateCommand request, CancellationToken cancellationToken)
        {
            var result = await _mediator.Send(request, cancellationToken);
            return result;
        }
    }
}
